perm filename MIDTER.S79[206,LSP] blob
sn#442096 filedate 1979-05-14 generic text, type T, neo UTF8
; Question # 1
a) As the problem asked for a RECURSIVE function, be prepared to argue if your
answer was
RDAC[ u ] ← a d REVERSE[ u ]
Better would be
RDAC[ u ] ← IF n d d u THEN u
ELSE RDAC[ d u ]
b) (DEFUN RDAC (U)
(COND ((NULL (CDDR U)) U)
(T (RDAC (CDR U)))))
c) We have assumed that U is a list, which has at least 2 elements.
In general, we should check that these conditions hold:
RDAC[ u ] ← IF at u ∨ at d u THEN ERROR1[ '(|Not a (long enough) list!|) ]
; (↑) as u might be NIL
ELSE IF n d d u THEN u
ELSE RDAC[ d u ]
(Note: With clever coding, we could certainly eliminate some of these checks.)
; Question # 2
a) ( (A . WORD) IS NOT A . WORD)
b) (SETQ AW '(A . WORD))
(CONS AW (CONS 'IS (CONS 'NOT AW)))
or
(SETQ ANSWER (CONS 'DUMMY (CONS 'IS (CONS 'NOT CONS 'A 'WORD))))
(RPLACA ANSWER (CDDDR ANSWER))
c) ((LAMBDA (AW)
(CONS AW (CONS 'IS (CONS 'NOT AW))))
'(A . WORD))
; Question # 3
(DEFUN CPRINT (ARG)
((LAMBDA (NOVICE)
(MAPC '(LAMBDA (X)
(COND ((ATOM X) (PRINT-1 X))
; Here we know it is non-atomic. We assume a list:
(NOVICE (MAPC 'PRINT-1 X))))
ARG))
(NOT (GET USERNAME 'EXPRIENCED))))
(DEFUN PRINT-1 (Y)
; This prints Y, then a SPACE
(PRINC Y) (PRINC '| |))
[It may be wise to use some form of error checking at various places.]
; Question # 4
a)
(DEFUN DELAMB (X)
((LAMBDA (V E Q) ; these refer to same names as in problem statement
(COND ((= 1. (NUM-TIMES V E)) (SUBST Q V E))
(T X))) ; else, do nothing
(CAR (CADAR X))
(CADDR X)
(CADR X)))
(DEFUN NUM-TIMES (VAR EXPR)
(COND ((EQ VAR EXPR) 1.) ; only equal when EXPR is atom [as VAR is]
((ATOM EXPR) 0.) ; all other atoms contribute nothing
(T (PLUS (NUM-TIMES VAR (CAR EXPR)) (NUM-TIMES VAR (CDR EXP))))))
; We could be clever, and, if, say, (CAR EXPR) = 'QUOTE, ignore the CDR
; ... but that's a lot of work for not much return.
b) This will get into trouble whenever this Z EVALuates to any expression
involving the value of Y, as this value will NOT be bound to (MAXIM INCOMES)
when the basic expression, E, is evaluated. This will then give an error
is Y had no previous binding, or use that earlier Y value.
; Question # ?
For one extra credit point, that mysterious hacker was
Lee Ermin